// crawler
package main

import (
	"fmt"
	"time"

	"gopkg.in/go-module/log.v1"

	"gitee.com/Flearning/go_crawl/modules"
	"gitee.com/Flearning/go_crawl/setting"
)

func main() {
	start := time.Now()
	var crawlUrl string
	startInit()

	mr := new(modules.ReqCrawlInfo)
	rb, err := mr.ReadCrawlInfoFile()
	if err != nil {
		log.Fatal(4, "Read file Error: %v", err)
	}
	mr = mr.New(rb)

	log.Info("Crawler URL: %s", mr.Url)
	log.Info("Crawler Prames Lenght: %d", len(mr.Prames))

	crawlCh := make(chan string, len(mr.Prames))
	for _, val := range mr.Prames {
		crawlUrl = fmt.Sprintf(mr.Url, val.Symbol, val.Source, val.Page, val.Sort)
		crawlCh <- crawlUrl
	}
	close(crawlCh)
	for s := range crawlCh {
		fmt.Println(s)
	}

	log.Info("cmd time: %s", time.Since(start))
	time.Sleep(time.Millisecond)
}

func startInit() {
	setting.NewConfigContext()
	setting.NewLogService()
}
